﻿using System.Collections;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using RazakiBLL.Entities;

namespace RazakiBLL.Managers
{
    public class MessageTypeRps : RpsRazaki<MessageType>
    {
        public MessageTypeRps(ObjectContext context)
            : base(context)
        {
        }

        private IEnumerable<MessageType> GetAllWithCache()
        {
            var messageTypes = UtilitiesBLL.CacheProvider.GetData<List<MessageType>>("MessageType");

            if (messageTypes == null)
            {
                messageTypes = GetAll();
                UtilitiesBLL.CacheProvider.SetData("MessageType", messageTypes);
            }

            return messageTypes;
        }

        public MessageType GetByType(string type)
        {
            MessageType result = GetAllWithCache().Where(x => x.Type == type).FirstOrDefault();

            return result;
        }
    }
}